// pages/translate/translate.js
Page({
  data: {
    origin_info: '',
    result_info: ''
  },

  change_origin: function (e) {
    const res = e.detail.value
    this.setData({
      origin_info: res,
    })
  },

  translate: function () {
    const temp = this.data.origin_info
    var urlParams = "https://fanyi.youdao.com/openapi.do?keyfrom=f2ec-org&key=1787962561&type=data&doctype=json&version=1.1&q=";
    wx.request({
      url: urlParams + temp,
      // data: params.data,
      header: { 'content-type': 'application/x-www-form-urlencoded' },
      method: 'GET',
      success: (res) => {
        const resData = res.data.basic;
        if (resData) {
          this.setData({
            result_info: resData.explains[0]
          })
        } else {
          this.setData({
            result_info: 'sorry,暂无该翻译,我们会很快完善'
          })
        }
      }
    })
  },
})